{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "My name is Python and I'm 27 years old\n"
     ]
    }
   ],
   "source": [
    "class A:\n",
    "    \n",
    "    def __init__(self, name, age):\n",
    "        self.__name = name\n",
    "        self.__age = age\n",
    "    \n",
    "    def get_name(self):\n",
    "        return self.__name\n",
    "    \n",
    "    def get_age(self):\n",
    "        return self.__age\n",
    "    \n",
    "    def __str__(self):\n",
    "        return \"My name is {} and I'm {} years old\".format(self.__name, self.__age)\n",
    "\n",
    "a = A('Python', 27)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "27"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.get_age()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "class B:\n",
    "    \n",
    "    def __init__(self, name, age):\n",
    "        self.__name = name\n",
    "        self.__age = age\n",
    "    \n",
    "    @property\n",
    "    def name(self):\n",
    "        return self.__name\n",
    "    \n",
    "    @property\n",
    "    def age(self):\n",
    "        return self.__age\n",
    "    \n",
    "    @age.setter\n",
    "    def age(self, value):\n",
    "        self.__age = value\n",
    "    \n",
    "    def __str__(self):\n",
    "        return \"My name is {} and I'm {} years old\".format(self.__name, self.__age)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "b = B('Demo', 30)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "My name is Demo and I'm 30 years old\n"
     ]
    }
   ],
   "source": [
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "b.age = 40"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "My name is Demo and I'm 40 years old\n"
     ]
    }
   ],
   "source": [
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
